package ui.uea;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import ui.login_ui.Mouse;

@SuppressWarnings("serial")
public class AddModelPanel extends JPanel{
	private UEAPicturePath path = new UEAPicturePath();

	//[x=187,y=86][x=424,y=105]
	private Rectangle nameRect = new Rectangle(187,86,424 - 187,105 - 86);
	private JTextField modelNameField;
	//[x=189,y=111][x=423,y=130]
	private Rectangle hcreditRect = new Rectangle(187,111,424 - 187,130 - 111);
	private JTextField hcreditField;
	//[x=190,y=138][x=424,y=157]
	private Rectangle tcreditRect = new Rectangle(187,138,424 - 187,157 - 138);
	private JTextField tcreditField;
	
	//[x=54,y=199][x=197,y=226]
	private Rectangle addButtonRect = new Rectangle(54,199,197 - 54,226 - 199);
	private JLabel addButton;
	private MouseListener addButtonListener;
	//[x=283,y=197][x=423,y=228]
	private Rectangle cancelButtonRect = new Rectangle(283,197,423 - 283,228 - 197);
	private JLabel cancelButton;
	private MouseListener cancelButtonListener;
	
	
	public AddModelPanel(){
		this.setLayout(null);
		
		initModelName();
		this.add(modelNameField);
		
		initHcreditName();
		this.add(hcreditField);
		
		initTcreditName();
		this.add(this.tcreditField);
		
		initAddButton();
		this.add(this.addButton);
		
		initCancelButton();
		this.add(this.cancelButton);
		
		this.addMouseListener(new Mouse());
	}
	public MouseListener getAddButtonListener() {
		return addButtonListener;
	}
	public void setAddButtonListener(MouseListener addButtonListener) {
		this.addButton.addMouseListener(addButtonListener);
	}
	public MouseListener getCancelButtonListener() {
		return cancelButtonListener;
	}
	public void setCancelButtonListener(MouseListener cancelButtonListener) {
		this.cancelButton.addMouseListener(cancelButtonListener);
	}
	public String getName(){
		return modelNameField.getText();
	}
	public String getHcredit(){
		return hcreditField.getText();
	}
	public String getTcredit(){
		return tcreditField.getText();
	}
	private void initModelName(){
		
		modelNameField = new JTextField();
		modelNameField.setBounds(nameRect);
		modelNameField.setOpaque(false);
		modelNameField.setBorder(new EmptyBorder(0,0,0,0));
		
	}
	private void initHcreditName(){
		
		hcreditField = new JTextField();
		hcreditField.setBounds(hcreditRect);
		hcreditField.setOpaque(false);
		hcreditField.setBorder(new EmptyBorder(0,0,0,0));
	}
	private void initTcreditName(){
		
		tcreditField = new JTextField();
		tcreditField.setBounds(tcreditRect);
		tcreditField.setOpaque(false);
		tcreditField.setBorder(new EmptyBorder(0,0,0,0));
		
	}
	private void initAddButton(){
		addButton = new JLabel();
		addButton.setBounds(addButtonRect);
		addButton.setOpaque(false);
	}
	private void initCancelButton(){
		cancelButton = new JLabel();
		cancelButton.setBounds(cancelButtonRect);
		cancelButton.setOpaque(false);
	}
	@Override 
	protected void paintComponent(Graphics g){
		super.paintComponent(g);
		BufferedImage im = null;
		try {
			 im = ImageIO.read(new File(path.getAddModelPanel()));
		} catch (IOException e) {
			e.printStackTrace();
		}
		g.drawImage(im, 0, 0,this.getWidth(),this.getHeight(), null);
	}
}
